﻿using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using BeatEmUp.Items.Weapons;
using System;

namespace BeatEmUp.HUD
{
    class PlayersHUD
    {
        Vector2 picturePosition;
        Texture2D line;
        Rectangle fieldRect;
        SpriteFont hpFont;
        SpriteFont playerFont;
        Texture2D playerPicture;
        int playerID;
        public static int hudEnd = 0;

        public PlayersHUD(int playerID)
        {
            this.playerID = playerID;
            switch (playerID)
            {
                case 1:
                    picturePosition = new Vector2(20, 20);
                    break;
            }
            
        }

        public void LoadContent(ContentManager content,GraphicsDevice graphicsDevice)
        {
            HPDisplay.barBack = content.Load<Texture2D>(@".\Sprites\HUD\HP bar back");
            HPDisplay.singleHealth = content.Load<Texture2D>(@".\Sprites\HUD\HP single");
            playerPicture = content.Load<Texture2D>(@".\Sprites\HUD\Player picture "+playerID);
            playerFont = content.Load<SpriteFont>(@".\Fonts\Player");
            hpFont = content.Load<SpriteFont>(@".\Fonts\HPStatus");
            hudEnd = (int)picturePosition.Y + playerPicture.Height + 5;
            line = new Texture2D(graphicsDevice, 1, 1, false, SurfaceFormat.Color);
            line.SetData(new[] { Color.White });
        }

        public void Draw(SpriteBatch sb,Player player,Weapon weapon)
        {
            switch(playerID)
            {
                case 1:
                    sb.Draw(playerPicture, new Rectangle((int)picturePosition.X,(int)picturePosition.Y,playerPicture.Width,playerPicture.Height), Color.White);
                    sb.DrawString(playerFont, "Player", new Vector2(player.characterHP.healthBarPosition.X, picturePosition.Y), Color.Black);
//                    sb.DrawString(playerFont, "Player " + playerID, new Vector2(player.characterHP.healthBarPosition.X, picturePosition.Y), Color.Black);
                    player.characterHP.DrawWithoutScale(sb, player.HPPercentage());
                    sb.DrawString(hpFont, "Level: " + player.GetLevel(), player.characterHP.DrawBarBackWithoutScale(sb), Color.White);
                    sb.DrawString(hpFont, player.HP.ToString() + " / " + player.MaxHP.ToString(), new Vector2(player.characterHP.healthBarPosition.X + 5, player.characterHP.healthBarPosition.Y + 1), Color.White);
                    sb.DrawString(hpFont, weapon.GetWeaponDescription(), new Vector2(player.characterHP.healthBarPosition.X + 110, picturePosition.Y), Color.Black);
                    break;
            }
            DrawLine(sb, line, 3, Color.Black, new Vector2(0, PlayersHUD.hudEnd), new Vector2(MovementBoundaries.gameField.Width, PlayersHUD.hudEnd));
        }

        void DrawLine(SpriteBatch batch, Texture2D blank,
              float width, Color color, Vector2 point1, Vector2 point2)
        {
            float angle = (float)Math.Atan2(point2.Y - point1.Y, point2.X - point1.X);
            float length = Vector2.Distance(point1, point2);

            batch.Draw(blank, point1, null, color,
                       angle, Vector2.Zero, new Vector2(length, width),
                       SpriteEffects.None, 0);
        }

        
    }
}
